﻿using Castle.DynamicProxy;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Mvc;

namespace CNKI.TPI.Web.Base
{
    public class BaseApiController : ApiController
    {
        protected ProxyGenerator generator;
        private Stopwatch sw;

        public BaseApiController()
        {
            generator = new ProxyGenerator();
            sw = new Stopwatch();
        }

        ////
        //// 摘要:
        ////     在调用操作方法前调用。
        ////
        //// 参数:
        ////   filterContext:
        ////     有关当前请求和操作的信息。
        //protected override void OnActionExecuting(ActionExecutingContext filterContext)
        //{
        //    string controller = filterContext.RouteData.Values["controller"].ToString();
        //    string action = filterContext.RouteData.Values["action"].ToString();
        //    LogOpr.Debug(0, 0, controller + "Controller", action, "", "", "Recive request = " + Request.RequestUri);
        //    sw.Start();
        //}
        ////
        //// 摘要:
        ////     在调用操作方法后调用。
        ////
        //// 参数:
        ////   filterContext:
        ////     有关当前请求和操作的信息。
        //protected override void OnActionExecuted(ActionExecutedContext filterContext)
        //{
        //    sw.Stop();
        //    string controller = filterContext.RouteData.Values["controller"].ToString();
        //    string action = filterContext.RouteData.Values["action"].ToString();
        //    LogOpr.Debug(1, sw.ElapsedMilliseconds, controller + "Controller", action, "", "", "End request");
        //}

        protected string GetHeader(string key)
        {
            IEnumerable<string> keys = null;
            if (!Request.Headers.TryGetValues(key, out keys))
                return "";

            return keys.First();
        }
    }
}
